package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @ClassName: BrandController
 * @Package: com.atguigu.spzx.manager.controller
 * @Description 品牌管理
 * @Author 孤妤
 * @Date: 2023/12/7 15:03
 */
@Tag(name = "品牌管理")
@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @GetMapping("/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询品牌管理列表")
    public Result<PageInfo<Brand>> findBrandByPage(@PathVariable Integer pageNum,
                                               @PathVariable Integer pageSize){
        PageInfo<Brand> brandList = brandService.findBrandPage(pageNum,pageSize);
        return Result.build(brandList, ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    @Operation(summary = "添加品牌信息")
    public Result addBrand(@RequestBody Brand brand){
        brandService.addBrand(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("添加成功");
    }
    @GetMapping("/getById/{id}")
    @Operation(summary = "根据id查看品牌信息")
    public Result<Brand> findBrandById(@PathVariable Long id){
        Brand brand = brandService.findBrandById(id);
        return Result.build(brand,ResultCodeEnum.SUCCESS);
    }
    @PutMapping("/updateById")
    @Operation(summary = "修改品牌信息")
    public Result changeBrandById(@RequestBody Brand brand){
        brandService.changeBrandById(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("修改成功");
    }
    @DeleteMapping("/deleteById/{id}")
    @Operation(summary = "删除品牌信息")
    public Result removeBrandById(@PathVariable Long id){
        brandService.removeBrandById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("删除成功");
    }
    @GetMapping("/findAll")
    @Operation(summary = "查询所有品牌信息")
    public Result<List<Brand>> findAllBrand(){
        List<Brand> brandList = brandService.findAllBrand();
        return Result.build(brandList,ResultCodeEnum.SUCCESS);
    }
}
